package com.example.administrator.myapplication;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;

import com.example.administrator.myapplication.adapter.MyAdapter;
import com.example.administrator.myapplication.fragment.Fragment1;
import com.example.administrator.myapplication.fragment.Fragment2;
import com.example.administrator.myapplication.fragment.Fragment3;


import java.util.ArrayList;

public class Main2Activity extends AppCompatActivity {

    private ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initEvent();
    }
    //设置好基本布局 使用viewpager控件
    //创建好fragment
    //创建viewpager适配器
    //将fragment添加到适配器上

    private void initView() {
        viewPager = (ViewPager) findViewById(R.id.viewpager);
        Fragment1 f1 = new Fragment1();
        Fragment2 f2 = new Fragment2();
        Fragment3 f3 = new Fragment3();

        ArrayList a = new ArrayList();
        a.add(f1);
        a.add(f2);
        a.add(f3);

        viewPager.setAdapter(new MyAdapter(getSupportFragmentManager(),Main2Activity.this,a));
        viewPager.setCurrentItem(3);
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private void initData() {

    }

    private void initEvent() {

    }

}